<template>
  <div class="monitoring-echart">
    <div class="title">{{ echartData.title }} （{{ echartData.num }}）</div>
    <div ref="$echart" class="chart"></div>
  </div>
</template>

<script>
  import { defineComponent, onMounted, nextTick, ref } from 'vue';
  import * as echarts from 'echarts';

  export default defineComponent({
    name: 'EchartView',
    components: {},
    props: {
      echartData: {
        type: Object,
        default: () => {
          return {};
        },
      },
    },
    setup(props) {
      const $echart = ref();
      const initChart = () => {
        var myChart = echarts.init($echart.value);
        var option;

        option = {
          tooltip: {
            trigger: 'item',
            formatter: '{b}：{c}（{d}%）',
          },
          legend: {
            show: true,
            orient: 'vertical',
            bottom: '0px',
            left: '20px',
            data: ['未结束', '已结束'],
          },
          label: {
            show: true,
            formatter: '{b}：{c}（{d}%）',
          },
          color: ['#D3D9D2', '#40A25C'],
          series: [
            {
              name: '所有流程',
              type: 'pie',
              radius: ['50%', '70%'],
              avoidLabelOverlap: false,
              data: props.echartData.data,
            },
          ],
        };

        option && myChart.setOption(option);
      };
      onMounted(() => {
        nextTick(() => {
          initChart();
        });
      });

      return { $echart };
    },
  });
</script>
<style lang="less" scoped>
  .monitoring-echart {
    height: 100%;
    .title {
      height: 40px;
      height: 40px;
      line-height: 40px;
      font-size: 16px;
      padding-left: 20px;
      font-weight: bold;
    }
    .chart {
      height: 240px;
    }
  }
</style>
